# 物体检测

import cv2

# 加载物体检测器
cascade = cv2.CascadeClassifier('./module/haarcascade_frontalface_default.xml') # 前脸检测模块

# 读取图像
image = cv2.imread('./static/5.png')

# 转换为灰度图像
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 物体检测
objects = cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))

# 绘制边界框
for (x, y, w, h) in objects:
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

# 显示图像
cv2.imshow('Object Detection', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
